// webpack.config.js

const path = require("path");
// 引入html-webpack-plugin插件
const HtmlWebpackPlugin = require("html-webpack-plugin");
// 引入clean-webpack-plugin
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
// 引入webpack插件
const webpack = require("webpack");
module.exports = {
  mode: "development",
  devtool: "eval",
  devServer: {
    static: {
      directory: path.join(__dirname, "./dist"),
    },
    open: true,
    hot: true,
    client: {
      logging: "error", //只打印报错，其实只要这个配置就好了
      overlay: {
        //有报错发生，直接覆盖浏览器视窗，显示错误
        errors: true,
        warnings: false,
      },
    },
  },
  entry: "./computed-watch/index.js",
  output: {
    filename: "bundle.js",
    path: path.resolve(__dirname, "./dist"),
  },
  devtool: "inline-source-map", //inline-source-map  或者 source-map进行本地调试
  module: {
    rules: [
      {
        test: /\.js$/,
        loader: "babel-loader",
        exclude: /node_modules/,
      },
    ],
  },
  plugins: [
    new HtmlWebpackPlugin({
      // 往dist里塞html并且把bundle搞进去
      template: "./computed-watch/index.html",
    }),
    new CleanWebpackPlugin(), // 执行时间，在打包之前执行,改变输出文件后，下一次打包可以清除老文件
    new webpack.HotModuleReplacementPlugin(), // 更新后不会刷新，保留后加的数据
  ],
};
